var a = require("../../../utils/function.js"), t = getApp(), e = require("../../../api.js");

Page({
    data: {
        img: a.driverImg,
        money: 0,
        balance: 0,
        maxmoney: 0,
        distribution: "",
        yue: 0
    },
    onLoad: function(a) {
        console.log(a), this.setData({
            yue: a.yue,
            distribution: a.distribution
        });
    },
    onShow: function() {
        var a = this;
        t.request({
            url: e.bank.getdefault,
            method: "post",
            data: {
                type: 1,
                default: 1
            },
            state: 1,
            success: function(t) {
                console.log(t), 1 == t.code && a.setData({
                    data: t.data,
                    bank_number: t.data.banknum.slice(-4),
                    money: t.data.price
                });
            }
        }), t.request({
            url: e.bank.get_maxmoney,
            method: "post",
            data: {
                type: 1,
                default: 1
            },
            state: 1,
            success: function(t) {
                console.log(t), 1 == t.code && a.setData({
                    maxmoney: t.data.price
                });
            }
        });
    },
    changeInputData: function(a) {
        var t = this, e = a.currentTarget.dataset.name, n = a.detail.value;
        "balance" == e && t.setData({
            balance: n
        });
    },
    userWithdrawal: function(a) {
        var n = this;
        t.request({
            url: e.user.apply,
            method: "post",
            data: {
                price: a,
                bcard_num: n.data.data.banknum,
                bankname: n.data.data.bankname,
                type: 1
            },
            success: function(a) {
                console.log("提现申请结果", a), wx.hideLoading(), 1 == a.code ? (wx.showToast({
                    title: a.msg,
                    icon: "none",
                    mask: !0,
                    duration: 2e3
                }), setTimeout(function() {
                    wx.navigateBack({
                        delta: 1
                    });
                }, 2e3)) : wx.showToast({
                    title: a.msg,
                    icon: "none",
                    mask: !0
                });
            }
        });
    },
    distributionWithdrawal: function(a) {
        var n = this;
        t.request({
            url: e.distribution.apply,
            method: "post",
            data: {
                price: a,
                bcard_num: n.data.data.banknum,
                bankname: n.data.data.bankname,
                type: 1
            },
            success: function(a) {
                wx.hideLoading(), 1 == a.code ? (wx.showToast({
                    title: a.msg,
                    icon: "none",
                    mask: !0,
                    duration: 2e3
                }), setTimeout(function() {
                    wx.navigateBack({
                        delta: 1
                    });
                }, 2e3)) : wx.showToast({
                    title: a.msg,
                    icon: "none",
                    mask: !0
                });
            }
        });
    },
    sendRequest: function() {
        var a = this, t = a.data.balance, e = a.data.data;
        console.log("hjsancjd", t, e), wx.showLoading({
            mask: !0
        }), a.validate() && (1 == a.data.distribution ? a.userWithdrawal(t) : 2 == a.data.distribution && a.distributionWithdrawal(t));
    },
    validate: function() {
        var a = this, t = a.data.balance, e = a.data.money;
        return Number(t) < 1 ? (wx.showToast({
            title: "取现金额不足1元",
            icon: "none",
            mask: !0
        }), !1) : !(Number(t) > Number(e)) || (wx.showToast({
            title: "金额大于可提现金额",
            icon: "none",
            mask: !0
        }), !1);
    },
    click: function() {
        console.log("111"), wx.navigateTo({
            url: "/pages/driver/bankcard-list/index"
        });
    }
});